<?
	if (isset($page) && $page->pType == 2)
	{
		$cBlogs = json_decode($page->pText);
		$page->pText = '';
	}
	else
		$cBlogs = array();

?>

<form action="/admin/pages/add<?=(isset($page->id))?'/'.$page->id:''?>" method="post" id="pageForm">
<? if (isset($page->id)):?>
	<input type="hidden" name="id" value="<?=$page->id?>">
<? endif;?>
<table style="width:100%" class="noHighLight">
	<tr>
	<td style="width:300px; vertical-align:top;">
		<table>
			<tr>
				<td>Название</td>
				<td><input type="text" name="name" id="nameInput" value="<?=isset($page->pName)?$page->pName:''?>"></td>
			</tr>
			<tr>
				<td>Адрес</td>
				<td><input type="text" name="address" id="addressInput" value="<?=isset($page->pUrl)?$page->pUrl:''?>"></td>
			</tr>
			<tr>
				<td>Тип</td>
				<td>
					<select name="type" id="typeSelect">
						<option <?=(isset($page->pType) && ($page->pType == 0))?'selected':''?> value="0">Статичная</option>
						<option <?=(isset($page->pType) && ($page->pType == 1))?'selected':''?> value="1">Блог</option>
						<option <?=(isset($page->pType) && ($page->pType == 2))?'selected':''?> value="2">Лента</option>
						<option <?=(isset($page->pType) && ($page->pType == 3))?'selected':''?> value="3">Обратная связь</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>Пункт меню</td>
				<td><input type="checkbox" name="menu" <?=(isset($page->pMenu) && ($page->pMenu == 1))?'checked="checked"':''?>></td>
			</tr>
			<tr>
				<td>Главная</td>
				<td><input type="checkbox" name="main" <?=(isset($page->pMain) && ($page->pMain == 1))?'checked="checked"':''?>></td>
			</tr>
			<tr>
				<td>Подменю к</td>
				<td>
					<select name="tPage">
						<option value="0">Не является подменю</option>
						<? foreach ($pages as $pVal): ?>
							<option <?=(isset($page->tPage) && ($page->tPage == $pVal->id))?'selected':''?> value="<?=$pVal->id?>"><?=$pVal->pName?></option>
						<? endforeach; ?>
					</select>
				</td>
			</tr>
		</table>
		
		<input type="button" id="saveButton" value="Сохранить"/>
		<input type="submit" name="delete" value="Удалить"/>
	</td>
	
	<td>
		<div class="settingsBlock block">
			<div id="pageTextDiv" <?=(empty($page->pType) || (isset($page->pType) && ($page->pType==0 || $page->pType==3)))?'':'style="display:none"'?>>
				<!-- Статичная -->
				<label>
					<input type="radio" name="inputType" class="inputType" value="markitup" checked="true">MarkItUp
				</label>
				<label>
					<input type="radio" name="inputType" class="inputType" value="tinymce">TinyMCE
				</label>
				<div id="pageTextDiv_markitup">
					<textarea name="text_m" id="pageText"><?=isset($page->pText)?trim($page->pText):''?></textarea>
				</div>
				<div id="pageTextDiv_tinymce" style="display:none">
					<textarea name="text_t" id="pageText_tiny"><?=isset($page->pText)?trim($page->pText):''?></textarea>
				</div>
			</div>

			<div id="categoriesDiv" <?=(isset($page->pType) && ($page->pType==1))?"":'style="display:none"'?>>
				<!-- Блог -->
				<b>Количество статей в блоге</b> (0 - по умолчанию)<br>
				<input type="text" name="pBlogSize" id="bPageSize" value="<?=@abs($page->pBlogSize)?>">
				
				<div>
					<b>Вид блога:</b> <br>
					<label> <input type="radio" name="pType2" value="0" class="typeViewBlog" <? if ($page->pType2 == 0) echo "checked" ?> > Список </label>
					<label> <input type="radio" name="pType2" value="1" class="typeViewBlog" <? if ($page->pType2 == 1) echo "checked" ?> > Таблица </label>
				</div>

				<div id="typeTableViewBlog" <? if ($page->pType2 == 0) echo 'style="display:none"'; ?> >
					<b>Количество записей в строку (для табличного вида):</b> <br>
					<input type="text" name="pSize2" value="<?=@abs($page->pSize2)?>">
				</div>

				<b>Категории</b><br>
				<div id="categoriesListDiv">
				<? foreach ($categories as $category):?>
					<div data-id="<?=$category->id?>" class="oneCategory">
						<?=$category->pName?>
						<img src="<?=base_url()?>img/admin/remove.png" height="14" onClick="delCategory(this)" class="removeImg"/>
					</div>
				<? endforeach; ?>
				</div>
				<input type="hidden" id="delCategories" name="delCategories"/>
				<input type="hidden" id="newCategories" name="newCategories"/>
				<input type="text" id="newCategory"/>
				<br>
				<a href="javascript:addCategory();">Добавить категорию</a>
			</div>

			<div id="blogsDiv" <?=(isset($page->pType) && ($page->pType==2))?"":'style="display:none"'?>>
				<!-- Лента -->
				<b>Количество статей в ленте</b> (0 - по умолчанию)<br>
				<input type="text" name="pBlogSize" id="lPageSize" value="<?=@abs($page->pBlogSize)?>">
				<br>

				<b>Входящие в ленту блоги</b> <br>
				<? foreach ($blogs as $blog):?>
					<input type="checkbox" name="blog[]" value="<?=$blog->id?>" id="blog_<?=$blog->id?>" <?=(in_array($blog->id, $cBlogs))?'checked':''?>/>
						<label for="blog_<?=$blog->id?>"><?=$blog->pName?></label> <br/>
				<? endforeach; ?>
			</div>

			<div id="feedbackDiv" <?=(isset($page->pType) && ($page->pType==3))?"":'style="display:none"'?>>
				<!-- Обратная связь -->
				<table>
					<tr>
						<th>Заголовок</th>
						<th>Имя</th>
						<th>Тип</th>
						<th></th>
					</tr>
					<? if (!empty($feedback) && is_array($feedback)):
						foreach ($feedback as $val):?>
					<tr class="FBitem">
						<td><?=$val[0]?></td>
						<td><?=$val[1]?></td>
						<td><?=$val[2]?></td>
						<td class="removeFBitem"><a class="deleteFBitem">удалить</a></td>
					</tr>
					<? endforeach;endif; ?>
					<tr id="addItemTR">
						<td><input type="text" id="newFBtitle"></td>
						<td><input type="text" id="newFBname"></td>
						<td>
							<select id="newFBtype">
								<option value="text">text</option>
								<option value="textarea">textarea</option>
							</select>
						</td>
						<td><a href="javascript:addFBitem();">добавить</a></td>
					</tr>
				</table>
				<div id="feedbackHelpDiv">
					<b>pName</b> - имя пользователя <br>
					<b>pEmail</b> - email пользователя
				</div>
				<input type="hidden" id="feedbacks" name="feedback"/>
			</div>
		</div>
		<br>
		<div class="settingsBlock block">
			<b>Дополнительные стили:</b> <br>
			<div id="addStylesListDiv">
			<? foreach ($addStyles as $style):?>
				<div data-id="<?=$style->id?>" class="oneStyle">
					<?=$style->pUrl?>
					<img src="<?=base_url()?>img/admin/remove.png" height="14" onClick="delStyle(this)" class="removeImg"/>
				</div>
			<? endforeach; ?>
			</div>
			<input type="hidden" id="delAddStyles" name="delAddStyles"/>
			<input type="hidden" id="newAddStyles" name="newAddStyles"/>
			<input type="text" id="newStyle"/>
			<br>
			<a href="javascript:addStyle();">Добавить стиль</a>
			
			<hr>
			<b>Дополнительные скрипты:</b> <br>
			<div id="addScriptsListDiv">
			<? foreach ($addScripts as $script):?>
				<div data-id="<?=$script->id?>" class="oneScript">
					<?=$script->pUrl?>
					<img src="<?=base_url()?>img/admin/remove.png" height="14" onClick="delScript(this)" class="removeImg"/>
				</div>
			<? endforeach; ?>
			</div>
			<input type="hidden" id="delAddScripts" name="delAddScripts"/>
			<input type="hidden" id="newAddScripts" name="newAddScripts"/>
			<input type="text" id="newScript"/>
			<br>
			<a href="javascript:addScript();">Добавить скрипт</a>
		</div>

	</td>
	</tr>
</table>
</form>